package com.chendx.store.goods.controller;


import com.chendx.model.common.dtos.ResponseResult;
import com.chendx.model.goods.dto.CategoryDto;
import com.chendx.store.goods.service.CategoryService;
import com.chendx.store.api.goods.CategoryControllerApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by chendx on 2022/4/15.
 */
@RestController
@RequestMapping("/api/goods/category")
public class CategoryController implements CategoryControllerApi {

    @Autowired
    private CategoryService categoryService;

    @Override
    @PostMapping("/list")
    public ResponseResult findPage(@RequestBody CategoryDto dto) {
        return categoryService.findPage(dto);
    }

    @Override
    @GetMapping("/parentlist/{pid}")
    public ResponseResult findlist(@PathVariable Integer pid) {
        return categoryService.findByParentId(pid);
    }

    @Override
    @GetMapping("/categoryTree")
    public ResponseResult categoryTree() {
        return categoryService.categoryTree();
    }

    @Override
    @PostMapping("/add")
    public ResponseResult addCategory(@RequestBody CategoryDto dto) {
        return categoryService.add(dto);
    }

    @Override
    @PostMapping("/infos")
    public ResponseResult categoryInfos(@RequestBody CategoryDto dto) {
        return categoryService.infos(dto);
    }

    @Override
    @GetMapping("/ntlist")
    public ResponseResult findNoTemplateList() {
        return categoryService.findNoTemplateList();
    }

    @Override
    @GetMapping("/one")
    public ResponseResult oneInfo(Integer id) {
        return categoryService.oneInfo(id);
    }

    @Override
    @PutMapping("/update")
    public ResponseResult update(@RequestBody CategoryDto dto) {
        return categoryService.update(dto);
    }


}
